// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: GHZ Setup Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//

private alias Object.Value0 : Object.Timer     //	you know this one
private alias Object.Value1 : Object.CameraState     // which cam ur watching
private alias Object.Value2 : Object.Static     // for when an animatronic moves while you watch them

private alias Object.Value3 : Object.ActiveStatic
private alias Object.Value4 : Object.StaticTimer    // Which Camer frame
private alias Object.Value5 : Object.Bear5


public value BoxPositionY = 0;
public value CharacterTalking = 0;
public value TextActive = 0;
public value CutsceneActive = 0;



//if being stupid was a job

event ObjectMain
	switch object.state
	case 0
		object.timer = 255
		object.state++
	break
	case 1	//fade in
		if object.timer > -1
			object.timer -= 4
		else
			object.timer = 0	
		end if
		SetClassicFade(0, 0, 0, Object.Timer)	

		if Object[2].state == 4
			PlayMusic(0)
			object.state++
		end if
	break
	case 2

	break
	case 99 //EXIT FREDDY
		music.volume -= 8
		object.timer += 16
		SetClassicFade(0, 0, 0, Object.timer)
		if object.timer >= 255
			music.volume = 0
			StopMusic()
			stage.activeList = PRESENTATION_STAGE
			stage.listPos = 6
			LoadStage()				
		end if
	break	
	case 98	//NEW GAME
		music.volume -= 8
		object.timer += 16
		SetClassicFade(0, 0, 0, Object.timer)
		if object.timer >= 255
			music.volume = 0
			StopMusic()
			stage.activeList = BONUS_STAGE
			stage.listPos = 4
			options.gameMode = 1
			LoadStage()				
		end if
	break		
	case 97	//CONTINUE GAME
		music.volume -= 8
		object.timer += 16
		SetClassicFade(0, 0, 0, Object.timer)
		if object.timer >  255
			music.volume = 0
			options.gameMode = 1
			StopMusic()
			stage.activeList = BONUS_STAGE
			if saveRAM[6000] == 0	//night 1?
				stage.listPos = 4
			else	//the night you last left off
				temp0 = saveRAM[6000]
				temp0 += 3
				stage.listPos = temp0
			end if
			LoadStage()				
		end if
	break	
	case 96	//NIGHT 6
		music.volume -= 8
		object.timer += 16
		SetClassicFade(0, 0, 0, Object.timer)
		if object.timer >= 255
			music.volume = 0
			StopMusic()
			stage.activeList = BONUS_STAGE
			stage.listPos = 9
			LoadStage()				
		end if
	break		
	case 95	//NIGHT 6
		music.volume -= 8
		object.timer += 16
		SetClassicFade(0, 0, 0, Object.timer)
		if object.timer >= 255
			music.volume = 0
			StopMusic()
			stage.activeList = BONUS_STAGE
			stage.listPos = 2
			LoadStage()				
		end if
	break			
	end switch
end event

event ObjectDraw
	DrawRect(0, 0, screen.xsize, screen.ysize, 0, 0, 0, 255)
	object.inkeffect = INK_ALPHA

	object.alpha = 30

	Object.StaticTimer++
	if Object.StaticTimer == 1
		temp2 = 10
		Rand(temp3, 3)
		temp2 += temp3
		Object.StaticTimer = 0
	end if

	
	//Background	
	temp0 = 0
	FlipSign(temp0)
	while temp0 < screen.ysize
		temp1 = temp0
		FlipSign(temp1)
		while temp1 < screen.xsize
			DrawSpriteScreenFX(temp2, FX_INK, temp1, temp0)
			temp1 += 32
		loop
		temp0 += 32
	loop	

	object.alpha = 40

	if Object.Bear5 >= 99
		DrawSpriteScreenFX(15, FX_INK, screen.xcenter, 30)
	else
		DrawSpriteScreenFX(14, FX_INK, screen.xcenter, 30)
	end if

//	DrawNumbers(0, 32, 92, Object.Bear5, 3, 8, 0)
	

	if Object[2].state == 4
		if Object[2].alpha >= 255
			temp0 = screen.xcenter
			temp0 -= 26
			if saveRAM[6000] == 0
				DrawNumbers(0, temp0, 92, 1, 3, 8, 0)
			else
				DrawNumbers(0, temp0, 92, saveRAM[6000], 3, 8, 0)
			end if
		end if	
	end if
end event

event ObjectStartup
	LoadSpriteSheet("FNAF/Objects1.gif")

	SetMusicTrack("BearMenu.ogg", 0, 1)

	// 0-9 - Numbers 0-9
	SpriteFrame(0, 0, 8, 13, 558, 1)
	SpriteFrame(0, 0, 8, 13, 567, 1)
	SpriteFrame(0, 0, 8, 13, 576, 1)
	SpriteFrame(0, 0, 8, 13, 585, 1)
	SpriteFrame(0, 0, 8, 13, 594, 1)
	SpriteFrame(0, 0, 8, 13, 558, 15)
	SpriteFrame(0, 0, 8, 13, 567, 15)
	SpriteFrame(0, 0, 8, 13, 576, 15)
	SpriteFrame(0, 0, 8, 13, 585, 15)
	SpriteFrame(0, 0, 8, 13, 594, 15)

	//static
	SpriteFrame(0, 0, 32, 32, 992, 385)	//10
	SpriteFrame(0, 0, 32, 32, 992, 418)	//11
	SpriteFrame(0, 0, 32, 32, 992, 451)	//12
	SpriteFrame(0, 0, 32, 32, 992, 385)	//13

	SpriteFrame(-3, -6, 202, 217, 821, 560) //14
	SpriteFrame(-48, 6, 297, 208, 720, 778) //15

	

	// Place the HUD object into reserved object slot 4 and initialise its values
	Object[3].Type = TypeName[Freddy Menu]
	
	// The object should always be run, regardless if it's within camera bounds or not
	Object[3].Priority = PRIORITY_ACTIVE
	
	// Make the HUD draw ontop of all other sprites, too
	Object[3].DrawOrder = 5
	rand(Object[3].value5, 100)

end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("IIZ/Objects1.gif")
	SpriteFrame(0, 0, 64, 64, 153, 154)
end event
